Make parameter length based on underlying column length except for complex ops#2627
Open
simonsabin wants to merge 5 commits intoAzure:mainfrom
Open
Make parameter length based on underlying column length except for complex ops#2627simonsabin wants to merge 5 commits intoAzure:mainfrom
simonsabin wants to merge 5 commits intoAzure:mainfrom
Conversation
aaronburtle
reviewed
Mar 20, 2025
aaronburtle
reviewed
Mar 20, 2025
aaronburtle
reviewed
Mar 20, 2025
aaronburtle
reviewed
Mar 20, 2025
aaronburtle
reviewed
Mar 20, 2025
src/Service.Tests/SqlTests/GraphQLQueryTests/MsSqlGraphQLQueryTests.cs
Outdated
Show resolved
Hide resolved
aaronburtle
reviewed
Mar 20, 2025
Contributor
aaronburtle
left a comment
There was a problem hiding this comment.
This looks great, thank you for raising and then solving this issue. Just had a few nits, and a question.
Collaborator
Author
|
It’s to cover the edge case of matching with the LiKE that you get with contains and starts with, and also the escaping of values that occurs in the predicates. If you don’t you can end up with false positives and false negatives
Simon Sabin
________________________________
From: aaronburtle ***@***.***>
Sent: Thursday, March 20, 2025 9:19:26 PM
To: Azure/data-api-builder ***@***.***>
Cc: Simon Sabin ***@***.***>; Author ***@***.***>
Subject: Re: [Azure/data-api-builder] Make parameter length based on underlying column length except for complex ops (PR #2627)
@aaronburtle commented on this pull request.
________________________________
In src/Service.Tests/DatabaseSchema-MsSql.sql<#2627 (comment)>:
@@ -514,7 +514,7 @@ SET IDENTITY_INSERT books ON
INSERT INTO books(id, title, publisher_id)
VALUES (1, 'Awesome book', 1234),
(2, 'Also Awesome book', 1234),
-(3, 'Great wall of china explained', 2345),
+(3, 'Great wall of china explained]', 2345),
I am curious, why the extra "]"?
—
Reply to this email directly, view it on GitHub<#2627 (review)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AAJHM2Z7OZVBM5HTNT3F6SD2VMWF5AVCNFSM6AAAAABZOI6YHOVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZDOMBUGEZTOMRTG4>.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Collaborator
Author
|
applied suggested changes |
Contributor
|
/azp run |
|
Azure Pipelines successfully started running 6 pipeline(s). |
Contributor
|
Pipeline failures are just whitespace format. |
Aniruddh25
reviewed
Mar 24, 2025
Aniruddh25
reviewed
Mar 24, 2025
Collaborator
|
/azp run |
|
Azure Pipelines successfully started running 6 pipeline(s). |
Collaborator
|
/azp run |
|
Azure Pipelines successfully started running 6 pipeline(s). |
Collaborator
|
/azp run |
|
Azure Pipelines successfully started running 6 pipeline(s). |
Aniruddh25
reviewed
Mar 28, 2025
src/Service.Tests/SqlTests/GraphQLQueryTests/MsSqlGraphQLQueryTests.cs
Outdated
Show resolved
Hide resolved
Aniruddh25
reviewed
Mar 28, 2025
src/Service.Tests/SqlTests/GraphQLQueryTests/MsSqlGraphQLQueryTests.cs
Outdated
Show resolved
Hide resolved
Aniruddh25
reviewed
Mar 28, 2025
src/Service.Tests/SqlTests/GraphQLQueryTests/MsSqlGraphQLQueryTests.cs
Outdated
Show resolved
Hide resolved
Contributor
|
/azp run |
|
Azure Pipelines successfully started running 6 pipeline(s). |
Contributor
|
/azp run |
|
Azure Pipelines successfully started running 6 pipeline(s). |
|
thanks for perservering with this |
Contributor
|
/azp run |
|
Azure Pipelines successfully started running 6 pipeline(s). |
3189c7e to
bf4b8e9
Compare
…ations - Add Length property to DbConnectionParam and ColumnDefinition - Add GetLengthForParam to SourceDefinition for parameter length lookup - Pass lengthOverride flag through filter parsing chain for contains/startsWith/endsWith - Set SqlParameter.Size for VarChar/NVarChar/Char/NChar types in MsSqlQueryExecutor - Prevents implicit varchar(max) truncation when using LIKE with parameterized queries - Update ColumnDefinition field count assertion in serialization tests
bf4b8e9 to
b490f35
Compare
Contributor
|
/azp run |
|
Azure Pipelines successfully started running 6 pipeline(s). |
Session context parameters (used by sp_set_session_context) are string values that get SqlDbType.NVarChar inferred by default. Previously, the Size was set to -1 (varchar(max)) for all NVarChar parameters when no explicit Length was configured, causing sp_set_session_context to fail with 'An invalid parameter or option was specified'. Now Size is only set when DbConnectionParam.Length is explicitly non-null, which occurs only for query parameters where column metadata provides a length or when lengthOverride is set for LIKE operations.
Contributor
|
/azp run |
|
Azure Pipelines successfully started running 6 pipeline(s). |
Read ColumnSize from the schema DataTable during column introspection so that SqlParameter.Size is set to match the actual column length for string types (varchar, nvarchar, char, nchar). This completes the parameter length feature by wiring up the metadata source.
Contributor
|
/azp run |
|
Azure Pipelines successfully started running 6 pipeline(s). |
Contributor
|
/azp run |
|
Azure Pipelines successfully started running 6 pipeline(s). |
Populating Length from ColumnSize caused parameter.Size to be set for ALL string parameters (eq/neq), not just LIKE operations. This caused SQL Server to truncate parameter values to column length, breaking equality filters where the parameter value exceeds the column size.
733609d to
4a895ee
Compare
Contributor
|
/azp run |
|
Azure Pipelines successfully started running 6 pipeline(s). |
aaronburtle
approved these changes
Mar 12, 2026
Contributor
aaronburtle
left a comment
There was a problem hiding this comment.
Thanks again @simonsabin and sorry this was so delayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why make this change?
Closes #2626
What is this change?
Where a parameter is linked to an underlying column in the data model the length is stored
When the query is executed the length is used to ensure parameters have consistent lengths
For certain operations the value is padded with escape characters or %s, these need to be allowed for. In those cases the length is set to -1 (max) in order that the extra characters are allowed for AND consistent lengths are maintained
How was this tested?
Checking the resultant query is using the right length was done using trace. Not sure with the architecture whether it would be possible to mock at that level.
Sample Request(s)
See new tests TestFilterParamForStringFilterWorkWithComplexOp and TestFilterParamForStringFilterWorkWithNotContains